package com.maserb.monitor.service.schoolStudent.impl;

import com.alibaba.fastjson.JSONObject;
import com.maserb.monitor.common.HttpUtil;
import com.maserb.monitor.entity.card.AttendanceRecordEntity;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

@Service
public class ZhuowangService {
    //考勤信息发送给卓望的配置
    @Value("${zhuowang.url}")
    private String url;

    @Value("${zhuowang.appId}")
    private String appId;

    @Value("${zhuowang.ecCode}")
    private String ecCode;

    public void send(AttendanceRecordEntity record) throws UnsupportedEncodingException {
        //推送给卓望
        JSONObject data = new JSONObject();
        data.put("appid", appId);
        data.put("checkin_type", record.getOptType().toString());
        data.put("role", "1");
        data.put("stunum", record.getStudentId());
        data.put("eccode", ecCode);
        data.put("checkin_time", record.getStartTime());
        data.put("card_code", record.getCardId());
        data.put("img_src", "");
        data.put("terminal_id", record.getDeviceId());
        data.put("terminal_name", URLEncoder.encode("崇州", "UTF-8"));
        data.put("terminal_location", URLEncoder.encode("成都", "UTF-8"));

        Map<String, String> param = new HashMap<>();
        param.put("Data", URLEncoder.encode(data.toString(), "UTF-8"));
        param.put("MsgType", "APP_SEND_CARDCHECKIN_BYSTUNUM");

        String s = HttpUtil.getGetData(url, param);
        System.out.println(s);
    }
}
